import { Controller, Get, Inject, Post, Body, Delete, Param } from '@nestjs/common';
import { configure } from 'configure/configure.module';
import { FormValidatePipe } from '@utils/form-validate.pipe';
import { RegisterForm } from './user.forms';
import { UserService } from 'src/services/user.service';
import { NResponse } from '@type/response';
import { ErrorCode } from '@type/error-code';
@Controller(configure.appPrefix+'/user')
export class UserController {
    constructor(private userSrv: UserService){
    }
    @Post('/register')
    public async register(@Body(new FormValidatePipe()) form: RegisterForm): NResponse.IPost<null> {
        let user: RegisterForm & {createdUserId: string, updatedUserId: string} = Object.assign(form, {createdUserId: '', updatedUserId: ''})
        let [err, _] = await this.userSrv.register(user);
        if(err) {
            return {code: ErrorCode.UNKOWN, msg: '未知错误！', data: null};
        }
        return {code: ErrorCode.SUCCESS, msg: '成功！', data: null};
    }
    @Delete(':id')
    public async delete(@Param('id') id: string) {
        let [err, _] = await this.userSrv.remove(id);
        return {code: ErrorCode.SUCCESS, msg: '成功！', data: null};
    }
}